cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
    },

    // use this for initialization
    onLoad: function () {

    },

    init:function(pos,rotation){
        let speed = 300;
        let body = this.node.getComponent(cc.RigidBody);
        let angle = (180-rotation)*Math.PI/180;
        let ranAngle = angle+Math.PI/4*cc.randomMinus1To1(); 
        let targetPos = cc.v2(pos.x-700*Math.sin(ranAngle),pos.y-700*Math.cos(ranAngle));
        this.node.position = this.node.parent.convertToNodeSpaceAR(targetPos);
        this.node.rotation = 90-rotation;
        body.linearVelocity = cc.v2(speed*Math.sin(angle),speed*Math.cos(angle));
    },

    onBeginContact: function (contact, selfCollider, otherCollider) {
        let role = otherCollider.getComponent('role');
        role.speed = 0;
        role.speedTxt.string = '0';
        role.showTip('注意避开障碍物');
    },

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
